<template>
  <div>
    <ul>
      <li v-for="item in  messageList " :key="item.id">
        <!-- 跳转路由并携带params传参，to的字符串写法 -->
        <!-- <router-link :to="`/home/message/detail/${item.id}/${item.title}`">{{ item.title }}</router-link>&nbsp;&nbsp; -->

        <!-- 跳转路由并携带 params 传参，to的对象写法 -->
        <router-link :to="{
          name: 'xiangqing', //路由携带params 参数时，如果使用to的对象写法 必须用name 配置，不能使用path配置
          query: {
            id: item.id,
            title: item.title
          }
        }">
          {{ item.title }}
        </router-link>

        <button type="submit" @click="pushshow(item)">push查看</button>
        <button type="submit" @click="replaceshow(item)">replace查看</button>
      </li>
    </ul>
    <hr>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'Message',
  data() {
    return {
      messageList: [
        { id: "001", title: "消息内容001" },
        { id: "002", title: "消息内容002" },
        { id: "003", title: "消息内容003" },
        { id: "004", title: "消息内容004" },
      ]
    }
  },
  methods: {
    pushshow(item) {
      // console.log(this.$router)
      this.$router.push({
        name: "xiangqing",
        query: {
          id: item.id,
          title: item.title
        }
      })
    },
    replaceshow(item) {
      // console.log(this.$router)
      this.$router.replace({
        name: "xiangqing",
        query: {
          id: item.id,
          title: item.title
        }
      })
    },
  },
  beforeDestroy() {
    console.log('message即将被销毁了');
  },
}
</script>

<style lang="scss" scoped></style>